package com.qing.springcloud.controller;

import com.qing.springcloud.annotation.RequireLogin;
import com.qing.springcloud.annotation.ResponseResult;
import com.qing.springcloud.dto.message.MessageDTO;
import com.qing.springcloud.model.ChatMessage;
import com.qing.springcloud.service.MessageService;
import com.qing.springcloud.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author caozhipeng
 * @date 2025/7/21
 */
@RestController
@RequestMapping("/message")
@ResponseResult
@RequireLogin
public class MessageController {

    @Autowired
    private MessageService messageService;

    //    私聊
    @PostMapping("/sendPrivateMessage")
    public void sendPrivateMessage(@RequestBody ChatMessage message){
        messageService.sendPrivateMessage(message);
    }

    @PostMapping("/sendGroupMessage")
    public void sendGroupMessage(@RequestBody ChatMessage message){
        messageService.sendGroupMessage(message);
    }
    //    标记消息状态
    @PostMapping("/markMessageRead")
    public void markMessageRead(@RequestBody ChatMessage message){
        messageService.markMessageRead(message);
    }

    //    获取私聊信息记录
    @GetMapping("/getPrivateMessages")
    public PageResult<MessageDTO> getPrivateMessages(@RequestParam("userId") Long userId, @RequestParam("friendId") Long friendId, @RequestParam("page") long page, @RequestParam("size") long size){
        return messageService.getPrivateMessages(userId, friendId, page, size);
    }

    //    获取群聊消息记录
    @GetMapping("/getGroupMessages")
    public PageResult<MessageDTO> getGroupMessages(@RequestParam("groupId") Long groupId, @RequestParam("page") long page, @RequestParam("size") long size){
        return messageService.getGroupMessages(groupId, page, size);
    }
}
